package com.ultrapower.commons.utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;



import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

public class McAesencrypt {
//	private static String restUrl="http://localhost:8086/dacp/open/datams/sign/cryptApply.json";
//	private static String restUrl = "http://10.31.100.19/dataos/open/datams/sign/sensitiveTranslate.json";
	/** 20181211 更新加解密地址   by 胡晖 20181211*/
	private static String restUrl="http://10.31.100.19/dataos-new/open/datams/sign/sensitiveTranslate.json";

	private static String idUrl="http://10.31.100.19/dataos-new/open/datams/sign/sensitiveTranslate.json";
	private final static String key="pb3nu49840w3p1f";
	private final static String user="T00017";
	private final static JsonHelper jsh=JsonHelper.getInstance();
	public static void main(String[] args) throws  Exception{
		String str="201804010000";
		int i=Integer.parseInt(str.substring(0,10));
		System.out.println(i);
		//号码加密
		System.out.println("--------------------号码加密--------------");
		 Map<String,Object> crypt = new HashMap<String,Object>();
	      crypt.put("tenantId","T00017");
	      crypt.put("dsId","flow_map");
	      crypt.put("operType","aesencrypt");
	      crypt.put("defineId","phoneNo");
	      List<String> phonelist=new ArrayList<String>();
	      phonelist.add("18871310191");
	      phonelist.add("15172472825"); 
	      phonelist.add("15629174065");//dacp::M69HIFJWPxzZlnxKZXOYNA==
	      phonelist.add("00000000000");
	      crypt.put("content",phonelist);
	      String result= HttpHelper.post(user,key,restUrl,crypt);
	      System.out.println(result);
	      String success=JSONObject.parseObject(result).getString("success");
	      JSONArray toContent=JSONObject.parseArray(JSONObject.parseObject(result).getString("toContent").toString());
//	      System.out.println("success:"+success);
//	      System.out.println("toContent0:"+toContent.getString(0));
	      //号码解密
	      System.out.println("--------------------号码解密--------------");
	      Map<String,Object> crypt1 = new HashMap<String,Object>();
	      crypt1.put("tenantId","T00017");
	      crypt1.put("dsId","flow_map");
	      crypt1.put("operType","aesdecrypt");
	      crypt1.put("defineId","phoneNo");
	      List<String> phonelist1=new ArrayList<String>();
	      phonelist1.add("dacp::Vr0luykXAhQAFKnrd4IP5w==");
	      phonelist1.add("dacp::sgxULSlUswJynNFj4WIh8g==");
	      phonelist1.add("dacp::217JA0ZzG7pgalb7mJPPiw==");
	      phonelist1.add("dacp::O5ODk0gI6Y6CAOPdrMUCvw==");
	      phonelist1.add("dacp::Qav3WA5yCB6/j2W1tiCWRg==");
	      phonelist1.add("dacp::dQkHH4AxkTpNbn/OD8iP7Q==");//dacp::XLSphVO/JgaEgGyQeT9j8w==
	      phonelist1.add("dacp::Qav3WA5yCB6/j2W1tiCWRg==");
	      crypt1.put("content",phonelist1);
	      String result1= HttpHelper.post(user,key,restUrl,crypt1);
	      System.out.println(result1);
	      
	     //IMEI加密
	      System.out.println("--------------------IMEI加密--------------");
	      Map<String,Object> crypt2 = new HashMap<String,Object>();
	      crypt2.put("tenantId","T00017");
	      crypt2.put("dsId","flow_map");
	      crypt2.put("operType","aesencrypt");
	      crypt2.put("defineId","imei");
	      List<String> phonelis2=new ArrayList<String>();
//	      phonelis2.add("8622660396006700");
//	      phonelis2.add("8679270316112330");
	      phonelis2.add("0000000000000000");
	      crypt2.put("content",phonelis2);
	      String result2= HttpHelper.post(user,key,restUrl,crypt2);
	      System.out.println(result2);
	      
	    //IMEI解密
	      System.out.println("--------------------IMEI解密--------------");
	      Map<String,Object> crypt3 = new HashMap<String,Object>();
	      crypt3.put("tenantId","T00017");
	      crypt3.put("dsId","flow_map");
	      crypt3.put("operType","aesdecrypt");
	      crypt3.put("defineId","imei");
	      List<String> phonelis3=new ArrayList<String>();
	      phonelis3.add("dacp::LcQInTD/5EJAT/3PehUeS0U8cC/qXtugE1mAIfuxmNI=");
	      phonelis3.add("dacp::/qYZ0/5goU9ajys5TWUGsMfa8QlNiNng1htUjc3GoLk=");
	      phonelis3.add("dacp::NtBTM88d8S3cDEVbTNTS3+jnYw6tK+iKE/F8grnl/tQ=");
	      phonelis3.add("dacp::YRbgF9DEfsghwaDi3znj/MEbJiNKtRMQpHX4segL9S4=");
	      phonelis3.add("dacp::KLMLBL1/uK9im6nl1pf68dIKjGIR7tWQU76e/Wzbe3s=");
	      crypt3.put("content",phonelis3);
	      String result3= HttpHelper.post(user,key,restUrl,crypt3);
	      System.out.println(result3);
	      
	      
		    //身份证号解密
	      System.out.println("--------------------身份证号解密--------------");
	      Map<String,Object> crypt4 = new HashMap<String,Object>();
	      crypt4.put("tenantId","T00017");
	      crypt4.put("dsId","flow_map");
	      crypt4.put("operType","aesdecrypt");
	      crypt4.put("defineId","imei");
	      List<String> phonelis4=new ArrayList<String>();
	      phonelis4.add("dacp::XAi8amoGbCdh/MIy5qG0sJTqH7GF8As56W5giCMgTsI=");
	      phonelis4.add("dacp::x+XuAirXNqpvXyqi528Y9wktV2Vzg48I1X78Jiqd0IM=");
	      crypt4.put("content",phonelis4);
	      String result4= HttpHelper.post(user,key,restUrl,crypt4);
	      System.out.println(result4);
	      
	      System.out.println("--------------------身份证号解密--------------");
	      List<String> phonelis5=new ArrayList<String>();
	      Map<String,Object> crypt5 = new HashMap<String,Object>();
	      phonelis5.add("dacp::TVcdEwQ7HfiY5gfAX8PCxGTy/hBNB/cb3TO7r921vD0=");
	      phonelis5.add("dacp::jW1+2HUPRr/cucspurD22OTF8b+JSICWB08ek3+Ibvc=");
	      crypt5.put("tenantId","T00017");
	      crypt5.put("dsId","flow_map");
	      crypt5.put("operType","aesdecrypt");
	      crypt5.put("defineId","certificateNo");
	      crypt5.put("content",phonelis5);
	      String result5= HttpHelper.post(user,key,idUrl,crypt5);
	      System.out.println(result5);
	}
	
	/**
	 * 
		* @author: huhui
		* @date: 2018-4-24
		* @Description: 号码 IMEI 明文列表 列表加密
		* @param:  clearTextList: 号码 IMEI 明文列表   defineId: phoneNo/imei/certificateNo
		* @return: 
		* @throws:
		* 
		* ciphertextlist
	 */
	public static List<String> MCAesencrypt(List<String> clearTextList,String defineId) throws Exception{
		List<String> reslist=new ArrayList<String>();
		Map<String,Object> crypt = new HashMap<String,Object>();
	      crypt.put("tenantId","T00017");
	      crypt.put("dsId","flow_map");
	      crypt.put("operType","aesencrypt");
	      crypt.put("defineId",defineId);
	      List<String> list=clearTextList;
	      crypt.put("content",list);
	      String result= HttpHelper.post(user,key,restUrl,crypt);
//	      System.out.println(result);
	      boolean flag=JSONObject.parseObject(result).getBoolean("success");
	      JSONArray toContent=null;
	      if(flag){
	    	  toContent=JSONObject.parseArray(JSONObject.parseObject(result).getString("toContent").toString());
	    	  
	    	  for(int i=0;i<toContent.size();i++){
	    		  reslist.add(toContent.getString(i));
	    	  }
	    	  
	      }else{
	    	  System.out.println("加密失败...");
	    	  System.out.println("msg:"+JSONObject.parseObject(result).getString("msg"));
	      }
	      
	      return reslist;		
	}
	
	/**
	 * 
		* @author: huhui
		* @date: 2018-4-24
		* @Description:号码 IMEI 明文加密
		* @param: clearText : 号码/IMEI 明文; defineId: phoneNo/imei/certificateNo
		* @return: 
		* @throws:
	 */
	public  static String MCAesencrypt(String clearText,String defineId) throws Exception{
		String res=null;
		Map<String,Object> crypt = new HashMap<String,Object>();
	      crypt.put("tenantId","T00017");
	      crypt.put("dsId","flow_map");
	      crypt.put("operType","aesencrypt");
	      crypt.put("defineId",defineId);
	      List<String> list=new ArrayList<String>();
	      list.add(clearText);
	      crypt.put("content",list);
	      String result= HttpHelper.post(user,key,restUrl,crypt);
//	      System.out.println(result);
	      boolean flag=JSONObject.parseObject(result).getBoolean("success");
	      JSONArray toContent=null;
	      if(flag){
	    	  toContent=JSONObject.parseArray(JSONObject.parseObject(result).getString("toContent").toString());
	    	  res=toContent.getString(0);
	    	  
	      }else{
	    	  System.out.println("加密失败...");
	    	  System.out.println("msg:"+JSONObject.parseObject(result).getString("msg"));
	      }
	      return res;		
	}
	
	/**
	 * 
		* @author: huhui
		* @date: 2018-4-24
		* @Description:号码 IMEI 密文列表 列表解密
		* @param:  clearTextList: 号码 IMEI 密文列表   defineId: phoneNo/imei
		* @return: 
		* @throws:
	 */
	public static List<String> MCAesdecrypt(List<String> ciphertextlist,String defineId) throws Exception{
		List<String> reslist=new ArrayList<String>();
		Map<String,Object> crypt = new HashMap<String,Object>();
	      crypt.put("tenantId","T00017");
	      crypt.put("dsId","flow_map");
	      crypt.put("operType","aesdecrypt");
	      crypt.put("defineId",defineId);
	      List<String> list=ciphertextlist;
	      crypt.put("content",list);
	      String result= HttpHelper.post(user,key,restUrl,crypt);
	      boolean flag=JSONObject.parseObject(result).getBoolean("success");
	      JSONArray toContent=null;
	      if(flag){
	    	  toContent=JSONObject.parseArray(JSONObject.parseObject(result).getString("toContent").toString());
	    	  for(int i=0;i<toContent.size();i++){
	    		  reslist.add(toContent.getString(i));
	    	  }
	    	  
	      }else{
	    	  //System.out.println("解密失败...");
	    	  //System.out.println("msg:"+JSONObject.parseObject(result).getString("msg"));
	      }
	      return reslist;		
	}
	
	/**
	 * 
		* @author: huhui
		* @date: 2018-4-24
		* @Description:身份证解密
		* @param:  clearTextList: certificateNo
		* @return: 
		* @throws:
	 */
	public static List<String> MCAescertificateNo(List<String> ciphertextlist,String defineId) throws Exception{
		List<String> reslist=new ArrayList<String>();
		Map<String,Object> crypt = new HashMap<String,Object>();
	      crypt.put("tenantId","T00017");
	      crypt.put("dsId","flow_map");
	      crypt.put("operType","aesdecrypt");
	      crypt.put("defineId",defineId);
	      List<String> list=ciphertextlist;
	      crypt.put("content",list);
	      String result= HttpHelper.post(user,key,idUrl,crypt);
	      boolean flag=JSONObject.parseObject(result).getBoolean("success");
	      JSONArray toContent=null;
	      if(flag){
	    	  toContent=JSONObject.parseArray(JSONObject.parseObject(result).getString("toContent").toString());
	    	  
	    	  for(int i=0;i<toContent.size();i++){
	    		  reslist.add(toContent.getString(i));
	    	  }
	    	  
	      }else{
	    	  //System.out.println("解密失败...");
	    	  //System.out.println("msg:"+JSONObject.parseObject(result).getString("msg"));
	      }
	      return reslist;		
	}
	
	/**
	 * 
		* @author: huhui
		* @date: 2018-4-24
		* @Description:号码 IMEI 密文解密
		* @param: ciphertext: 号码 IMEI 密文   defineId: phoneNo/imei
		* @return: 
		* @throws:
	 */
	public  static String MCAesdecrypt(String ciphertext,String defineId) throws Exception{
		String res=null;
		Map<String,Object> crypt = new HashMap<String,Object>();
	      crypt.put("tenantId","T00017");
	      crypt.put("dsId","flow_map");
	      crypt.put("operType","aesdecrypt");
	      crypt.put("defineId",defineId);
	      List<String> list=new ArrayList<String>();
	      list.add(ciphertext);
	      crypt.put("content",list);
	      String result= HttpHelper.post(user,key,restUrl,crypt);
//	      System.out.println(result);
	      boolean flag=JSONObject.parseObject(result).getBoolean("success");
	      JSONArray toContent=null;
	      if(flag){
	    	  toContent=JSONObject.parseArray(JSONObject.parseObject(result).getString("toContent").toString());
	    	  res=toContent.getString(0);
	    	  
	      }else{
	    	  //System.out.println("解密失败...");
	    	  //System.out.println("msg:"+JSONObject.parseObject(result).getString("msg"));
	      }
	      return res;			
	}
	
	 
}
